{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9e2ea77e",
   "metadata": {},
   "source": [
    "# print()函数的使用"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1370e3f6",
   "metadata": {},
   "source": [
    "### 可以输出哪些内容："
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e613c2c2",
   "metadata": {},
   "source": [
    "> 可以输出数字\n",
    "\n",
    "> 可以输出字符串（带有双引号）\n",
    "\n",
    "> 可以输出含有运算符的表达式，可以输出运算的结果。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d36e18b",
   "metadata": {},
   "source": [
    "### 可以将内容输出的目的地"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f61d75c",
   "metadata": {},
   "source": [
    ">  显示器\n",
    "\n",
    ">  文件"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70a0b105",
   "metadata": {},
   "source": [
    "#### 将数据输出文件中,注意：1.所指定的盘要存在 2.使用file= fp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dc75757d",
   "metadata": {},
   "outputs": [],
   "source": [
    "fp=open('D:/')  ## 如果文件不存在就创建，存在就在文件内容的后面继续追加\n",
    "print(\"helloworld\",file=fp)\n",
    "fp.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ebd907a2",
   "metadata": {},
   "source": [
    "# 转义字符"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db1fd967",
   "metadata": {},
   "source": [
    "### 概念：反斜杠+想要实现的转义功能首字母"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8748dc10",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\n",
      "world\n"
     ]
    }
   ],
   "source": [
    "print('hello\\nworld') ## \\ + 转义功能的首字母  n-->newline的首字母表示换行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ada0e797",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\tworld\n"
     ]
    }
   ],
   "source": [
    "print('hello\\tworld')## 4个单元格为一个t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b9bdf22d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\bworld\n"
     ]
    }
   ],
   "source": [
    "print('hello\\bworld') ## \\b是退一个格子，将o覆盖了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3e90e220",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\r",
      "world\n"
     ]
    }
   ],
   "source": [
    "print('hello\\rworld')  ## world将hello进行了覆盖"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c39f0bf2",
   "metadata": {},
   "source": [
    "### 为什么需要？当字符串中包含反斜杠，单引号，双引号等有特殊用途的字符时，必须使用反斜杠对这些字符进行转义"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "519c000d",
   "metadata": {},
   "source": [
    "- 反斜杠 \\\\"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "13dd6d8a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "http:\\www.baidu.com\n"
     ]
    }
   ],
   "source": [
    "print('http:\\\\www.baidu.com')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "bf917be7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "http:\\\\www.baidu.com\n"
     ]
    }
   ],
   "source": [
    "print('http:\\\\\\\\www.baidu.com')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "76936a96",
   "metadata": {},
   "source": [
    "- 单引号\\’"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "9082251a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "老师说：'大家好'\n"
     ]
    }
   ],
   "source": [
    "print('老师说：\\'大家好\\'') ## 字符串里存在单引号"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c9ae11c",
   "metadata": {},
   "source": [
    "### 原字符，不希望字符串中的转义字符起作用，就使用原字符，就是在字符串之前加上r，或r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "859df91a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\\nworld\n"
     ]
    }
   ],
   "source": [
    "print(r'hello\\nworld')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "3ae983ca",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "EOL while scanning string literal (1310651087.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [15]\u001b[1;36m\u001b[0m\n\u001b[1;33m    print(r'hello\\nworld\\')\u001b[0m\n\u001b[1;37m                           ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\n"
     ]
    }
   ],
   "source": [
    "print(r'hello\\nworld\\')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f5019bcb",
   "metadata": {},
   "source": [
    "#### 注意事项，最后一个字符不能是反斜杠"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3116ca87",
   "metadata": {},
   "source": [
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "109ba795",
   "metadata": {},
   "source": [
    "# 变量的定义和使用"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a88905f2",
   "metadata": {},
   "source": [
    "## 变量由三部分组成"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93953a49",
   "metadata": {},
   "source": [
    "- 标识：表示对象所存储的内存地址，使用内置函数id()来获取\n",
    "- 类型：表示的是对象的数据类型，用type来获取\n",
    "- 值：具体数据，使用print()可以将值进行打印输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "54eea270",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4541c38b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f2b72310",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "512a65b7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e00f3a7b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "09c8d2c9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d745f28a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bd1af8c1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "79c40034",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
